<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">

        class Parent extends React.Component {
            constructor(props) {
                super(props);

                this.state = {
                    a: 5
                }
                console.log(this.state.a);
            }

            fn() {
                this.setState({
                    a: this.state.a + 1
                });
                console.log(this.state.a);
            }

            render() {
                console.log('父组件渲染了');
                return (
                    <div>
                        <Child a={this.state.a} />
                        父组件：{this.state.a} <br />
                        <input type="button" value="+1" onClick={this.fn.bind(this)} />
                    </div>
                );
            }
        }

        class Child extends React.Component {
            constructor(props) {
                super(props);
            }

            render() {
                console.log('子组件渲染了');
                return (
                    <div>
                        子组件：{this.props.a}
                    </div>
                );
            }
        }

        let oDiv = document.getElementById('app');

        ReactDOM.render(
            <Parent />,
            oDiv
        );
    </script>
</body>
</html>